#include <iostream>
#include <set>

using namespace std;

set<int> s[2];
int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		s[x].insert(i);
	}
	while (s[0].size() || s[1].size())
	{
		int p;
		if (s[1].empty() || (s[0].size() && *s[0].begin() < *s[1].begin()))
			p = 0;
		else p = 1;
		int x = 0;
		while (1)
		{
			auto t = s[p].upper_bound(x);
			if (t == s[p].end()) break;
			x = *t;
			cout << *t << " ";
			s[p].erase(t);
			p = !p;
		}
		cout << endl;
	}
	
	return 0;
}